//jquery content
//REF https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/onload
var wb;// 读取完成的数据
var rABS = false; // 是否将文件读取为二进制字符串
$(function() {
	$("#file1").change(
			function(obj) {
				var allStr ='' ;
				if (!obj.target.files) {
					alert("所选的不是文件,即将退出操作");
					return;
				}
				var fileFullName = obj.target.value;
				var f = obj.target.files[0];
				var fileName = f.name;
				$("#fileName1").val(fileFullName);
				// 新建文件读取
				var reader = new FileReader();
				// 加载数据
				/*console.log("当前readerstate是:");
				if(reader.readyState==0){
					console.log("0-还没有加载任何数据");
				}else if(reader.readyState==1){
					console.log("1-数据正在被加载");
				}else if(reader.readyState==2){
					console.log("2-已完成全部的读取请求");
				}*/
				console.log("加载数据");
				reader.onload = function(obj) {
					console.log("加载数据onloadend");
					//console.log(obj.target.result);
					var data = obj.target.result;
					//console.log("type: binary");
					wb = XLSX.read(data, {
						type : 'binary'
					});
					//console.log("print info");
					console.log(JSON.stringify(XLSX.utils
							.sheet_to_json(wb.Sheets[wb.SheetNames[0]])));
				};
				allStr = reader.readAsBinaryString(f);
				console.log(allStr);
				console.log("-------------end-------------");
				
				$.ajax({
					type:"post",
					url: $ctx+"/jsexcel/excelIn",
					data:allStr,
					datatype:"json",
					contentType: "application/json; charset=utf-8", 
					async: false,
			        error: function (data) {
			        	console.log("error:"+data);
			        },
			        success: function (data) {
			        	console.log("success:"+data);
			        }
			    });
		});//end of change function
	
	$("#button4").click(function(){
		console.log("button4 start work");
		var form = $("#form1");
		form.attr("action", $ctx+"/jsexcel/turnToLimitSizeAndType")
		form.submit();
		console.log("button4 end work");
	});
	
	$("#button5").click(function(){
		console.log("button5 start work");
		var form = $("#form1");
		form.attr("action", $ctx+"/jsexcel/turnToSignlePull")
		form.submit();
		console.log("button5 end work");
	});
});